<html>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>

<?php
date_default_timezone_set('UTC');

$username="bsc353_4";
$password="sonbeans";
$database="bsc353_4";


$ordernumber= intval($_POST['ordernumber']);



if($ordernumber=="Select One")
{
    echo"Error. Please select an Order Number";
}

else
{

mysql_connect("clipper.encs.concordia.ca",$username,$password) or die ("Unable to connect to database");

@mysql_select_db($database) or die ("Unable to select database");


// Check connection


$updatequery="Update Orders set status='Received' where orderNumber=$ordernumber";

//echo "query: $query \n"; 

mysql_query($updatequery) or die ("failed to update Order record");

$orderquery="Select ISBN,quantity,customerID,storeBranchID from Orders where orderNumber=$ordernumber"; 
$getorder=mysql_query($orderquery) or die ("failed to retrieve order");


$ISBN=mysql_result($getorder,0,"ISBN");
$quantity=intval(mysql_result($getorder,0,"quantity"));
$customerID=mysql_result($getorder,0,"customerID");
$storeBranchID=mysql_result($getorder,0,"storeBranchID");

//echo" $ISBN $quantity $customerID $storeBranchID";

if($storeBranchID=="")
    {
    $sendtowarehouse="INSERT INTO BookInWarehouse Values ('$ISBN',$quantity)";
    mysql_query($sendtowarehouse) or die ("failed to add to Warehouse");
    echo "Order Has been sent to the Warehouse";
    }
else
    {
    
    $sendtobookinstore="INSERT INTO BookInStore Values('$ISBN',$quantity,'$storeBranchID','$customerID')";
    mysql_query($sendtobookinstore) or die ("failed to add to BookInStore");
    echo "Order Has been sent to Book-In-Store";
    }

mysql_close();


}

?> 
</html>

